﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using AbpZeroTemplate.Authorization;
using AbpZeroTemplate.Authorization.Roles;
using AbpZeroTemplate.Authorization.Roles.Dto;
using AbpZeroTemplate.Web.Controllers;
using AbpZeroTemplate.Web.Swagger;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace AbpZeroTemplate.Api.Admin.Controllers
{
    /// <summary>角色
    /// </summary>
    [Area("Admin")]
    [Route("Admin/Role/[action]")]
    [ApiName("Admin")]
    [RemoteService]
    [AbpMvcAuthorize(AppPermissions.Pages_Administration_Roles)]
    public class RoleController : AbpZeroTemplateControllerBase
    {
        private readonly IRoleAppService _roleAppService;
        /// <summary>
        /// </summary>
        public RoleController(IRoleAppService roleAppService)
        {
            _roleAppService = roleAppService;
        }

        /// <summary>获取角色
        /// </summary>
        [HttpGet]
        public async Task<ListResultDto<RoleListDto>> GetRoles(GetRolesInput input)
        {
            return await _roleAppService.GetRoles(input);
        }

        /// <summary>获取用来编辑的角色
        /// </summary>
        [HttpGet]
        [AbpMvcAuthorize(AppPermissions.Pages_Administration_Roles_Create, AppPermissions.Pages_Administration_Roles_Edit)]
        public async Task<GetRoleForEditOutput> GetRoleForEdit(NullableIdDto input)
        {
            return await _roleAppService.GetRoleForEdit(input);
        }

        /// <summary>创建或者修改角色
        /// </summary>
        [HttpPost]
        public async Task CreateOrUpdateRole([FromBody]CreateOrUpdateRoleInput input)
        {
            await _roleAppService.CreateOrUpdateRole(input);
        }

        /// <summary>删除角色
        /// </summary>
        [HttpDelete]
        [AbpMvcAuthorize(AppPermissions.Pages_Administration_Roles_Delete)]
        public async Task DeleteRole([FromBody]EntityDto input)
        {
            await _roleAppService.DeleteRole(input);
        }

    }
}
